package com.gwd.task.repository;

import com.gwd.task.entity.ProjectModuleEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @author zhiyongming
 * @date 2020/11/19 19:08
 */
@Repository
public interface ProjectModuleRepository extends JpaRepository<ProjectModuleEntity, Long> {
    @Modifying
    @Transactional
    @Query(value = "delete from ProjectModuleEntity u where u.moduleId in ?1")
    void deleteByIdList(List<Long> idList);

    @Modifying
    @Transactional
    void deleteBySuperiorIn(List<Long> idList);

    @Query(value = "select u from ProjectModuleEntity u where u.projectId in ?1 order by u.superior")
    List<ProjectModuleEntity> findByProjectIdIn(List<Long> projectIdList);

    @Query(value = "select u from ProjectModuleEntity u where u.projectId=?1 order by u.superior")
    List<ProjectModuleEntity> findByProjectId(Long projectId);
}
